/*
*********************************************************************************************************
*                                               uC/OS-II
*                                        The Real-Time Kernel
*
*                        (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
*                                          All Rights Reserved
*
*   Validated Software Corporation, Lafayette, CO
*
*
*********************************************************************************************************
*/

#ifndef OS_CPU_H
#define OS_CPU_H

#include "c6x.h"
/*
*********************************************************************************************************
*                                              DATA TYPES
*                                         (Compiler Specific)
*********************************************************************************************************
*/

typedef unsigned char  BOOLEAN;
typedef unsigned char  INT8U;                    /* Unsigned  8 bit quantity                           */
typedef signed   char  INT8S;                    /* Signed    8 bit quantity                           */
typedef unsigned short INT16U;                   /* Unsigned 16 bit quantity                           */
typedef signed   short INT16S;                   /* Signed   16 bit quantity                           */
typedef unsigned int   INT32U;                   /* Unsigned 32 bit quantity                           */
typedef signed   int   INT32S;                   /* Signed   32 bit quantity                           */
typedef float          FP32;                     /* Single precision floating point                    */
typedef double         FP64;                     /* Double precision floating point                    */

typedef unsigned int   OS_STK;                   /* Each stack entry is 32-bit wide                    */

#define BYTE           INT8S                     /* Define data types for backward compatibility ...   */
#define UBYTE          INT8U                     /* ... to uC/OS V1.xx.  Not actually needed for ...   */
#define WORD           INT16S                    /* ... uC/OS-II.                                      */
#define UWORD          INT16U
#define LONG           INT32S
#define ULONG          INT32U

typedef unsigned int REGS;

   /*------------------------------------------------------------------------
     THE SP MUST BE ALIGNED ON AN 8-BYTE BOUNDARY.
     WHICH means that the framesize has to be a multiple of that
   ------------------------------------------------------------------------*/

typedef struct
{
   REGS
   // 64 core registers
           A0, A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15,
           A16, A17, A18, A19, A20, A21, A22, A23, A24, A25, A26, A27, A28, A29, A30, A31,
           B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13, B14, B15,
           B16, B17, B18, B19, B20, B21, B22, B23, B24, B25, B26, B27, B28, B29, B30, B31;
   REGS
  // 68 total for environment registers
        AMR_, CSR_, IER_, IRP_;
   } REGISTER_FRAME;

// CPU Interrupt Numbers

#define CPU_INT_RST          0x00
#define CPU_INT_NMI          0x01
#define CPU_INT_RSV1         0x02
#define CPU_INT_RSV2         0x03
#define CPU_INT4             0x04
#define CPU_INT5             0x05
#define CPU_INT6             0x06
#define CPU_INT7             0x07
#define CPU_INT8             0x08
#define CPU_INT9             0x09
#define CPU_INT10            0x0A
#define CPU_INT11            0x0B
#define CPU_INT12            0x0C
#define CPU_INT13            0x0D
#define CPU_INT14            0x0E
#define CPU_INT15            0x0F

#ifdef _TMS320C6X
/*
 * This declaration of CSR is required by MicroCOS files to disable interrupts.
 * It duplicates the declaration in c6x.h.  MicroCOS source files do not
 * #include c6x.h because to do so would couple them to the TI DSP.
 */
extern cregister volatile unsigned int CSR;

#define	OS_CRITICAL_METHOD 	3
#define OS_CPU_SR           unsigned int

#define	OS_ENTER_CRITICAL()	cpu_sr = (CSR & 0x00000001); CSR &= 0xFFFFFFFE; // disable interrupts

#define OS_EXIT_CRITICAL()  CSR |= cpu_sr;          // restore global interrupt status

#endif

#define  OS_TASK_SW()       OSCtxSw()

#define  OS_STK_GROWTH      1                       /* Stack grows from HIGH to LOW memory on C6205  */


/*
*********************************************************************************************************
*                                              CONSTANTS, structs, typedefs
*********************************************************************************************************
*/
#ifndef TRUE
#define TRUE     1
#define FALSE    0
#endif

/*
*********************************************************************************************************
*                                              VARIABLES
*********************************************************************************************************
*/

/*
*********************************************************************************************************
*                                         FUNCTION PROTOTYPES
*********************************************************************************************************
*/

unsigned int ReturnCurrentDP(void);
BOOLEAN areInterruptsEnabled (void);
BOOLEAN enableInterrupts (void);

#endif /* of OS_CPU_H */
